package com.xueqiu.movieplaymanagersystem.controller.admin;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xueqiu.movieplaymanagersystem.model.JsonResult;
import com.xueqiu.movieplaymanagersystem.entity.Visit;
import com.xueqiu.movieplaymanagersystem.service.VisitService;

/**
 * @author xueqiu
 */
@Controller
@RequestMapping("/admin")
public class VisitController {
    @Autowired
    private VisitService visitService;

    /**
     * 分页查询访问记录
     *
     * @param page  当前页码
     * @param limit 每页条数
     * @return 当前页数据；可能数量小于limit
     */
    @RequestMapping("/visit")
    @ResponseBody
    public JsonResult<Visit> findAll(int page, int limit) {
        //默认2个参数的分页查询的参数永远是合法的；大于-1
        JsonResult<Visit> jsonResult = new JsonResult<>();
        PageInfo<Visit> resultPageInfo = visitService.findAll(page, limit);
        // int count = (int)(((Page<Visit>)all).getTotal());
        jsonResult.Success(
                "查询访问记录成功！",
                resultPageInfo.getList(),
                (int) resultPageInfo.getTotal()
        );
        return jsonResult;
    }
}
